﻿<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="../images/favicon.ico">
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>


<!-- 文件上传需要的样式 -->

<link rel="stylesheet" type="text/css"
	href="${path }/resource/plugin/kindeditor/themes/default/default.css" />
<link rel="stylesheet" type="text/css"
	href="${path }/resource/plugin/kindeditor/plugins/code/prettify.css" />
<script type="text/javascript"
	src="${path }/resource/plugin/kindeditor/kindeditor.js"></script>
<script type="text/javascript"
	src="${path }/resource/plugin/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript"
	src="${path }/resource/plugin/kindeditor/plugins/code/prettify.js"></script>

<title></title>
</head>

<form class="form form-horizontal" method="post" style="display: none;"
	enctype="multipart/form-data" target="blankFrame"
	action="${path }/resource/plugin/kindeditor/zking_upload_json.jsp?fileType=image&hiddenId=photo&flag=img_1">
	<input id="fileText" type="file" multiple name="file-1"
		onchange="fileChange()" /> <input type="submit" id="submitBtn" />
</form>
<input id="hiddenImg" style="display: none;">
<iframe src="" name="blankFrame" id="blankFrame"
	style="height: 100px; width: 100px; display: none;"> </iframe>

<div class="ibox-content">
	<form class="form-horizontal" id="dataform"
		onsubmit="javascripr:return false;">

		<input type="hidden" name="tokenUrl" value="${tokenUrl}"> <input
			type="hidden" name="token" value="${token}">
		<c:if test="${obj ne null }">
			<input type="hidden" name="id" value="${obj.id }">
		</c:if>


		<input type="hidden" name=img value="${obj.img }" id="photo">
		<div class="form-group">
			<label class="col-sm-2 control-label">项目图片</label>
			<div class="col-sm-4">
				<c:if test="${obj.img eq null or obj.img eq ''}">
					<img width="150" id='img_1'
						src="${path}/resource/images/profile_small.jpg" class="" />
				</c:if>
				<c:if test="${obj.img ne null and obj.img ne ''}">
					<img width="150" id='img_1' src="${obj.img}" class="" />
				</c:if>
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-2 control-label">项目名称</label>
			<div class="col-sm-4">
				<input type="text" dataType="*1-20" class="form-control"
					name="projName" value="${obj.projName }">
				<div class="Validform_checktip"></div>
			</div>
			<label class="col-sm-2 control-label">客户</label>
			<div class="col-sm-4">
				<select class="select2 form-control" size="1" name="custId">
					<option value="">--请选择客户--</option>
					<c:forEach items="${clientList}" var="item">
						<option <c:if test="${obj.custId eq item.id }"> selected </c:if>
							value="${item.id }">${item.companyName }</option>
					</c:forEach>
				</select>
			</div>
		</div>


		<div class="form-group">
			<label class="col-sm-2 control-label">访问地址</label>
			<div class="col-sm-4">
		
				<input type="text" dataType="*1-100" class="form-control"
					value="<c:if test="${obj.url eq null or obj.url eq '' }">http://</c:if>${obj.url }" name="url" ignore="ignore">
				<div class="Validform_checktip"></div>
			</div>
			<label class="col-sm-2 control-label">git地址</label>
			<div class="col-sm-4">
				<input type="text" dataType="*1-100" class="form-control"
					value="<c:if test="${obj.url eq null or obj.url eq '' }">http://</c:if>${obj.url }" name="gitUrl" ignore="ignore">
				<div class="Validform_checktip"></div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">预计结束时间</label>
			<div class="col-sm-4">
				<input type="text" dataType="*1-100"
					class="form-control datetimepicker"
					value="<fmt:formatDate value="${obj.endTime }" pattern="yyyy-MM-dd" /> "
					name="endTime">
				<div class="Validform_checktip"></div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">项目编号</label>
			<div class="col-sm-4">
				<input type="text" dataType="*1-100" class="form-control"
					value="${obj.projNo}" name="projNo" nullmsg="项目编号不能为空">
				<div class="Validform_checktip"></div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">项目介绍</label>
			<div class="col-sm-4">
				<textarea dataType="*1-100" class="form-control" name="introduction">${obj.introduction }</textarea>
				<div class="Validform_checktip"></div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label"> 研发人员</label>
			<button class="btn btn-primary btn-sm" onclick="addMan()"
				type="button">添加人员</button>
		</div>
		<div id="manbox">
		<c:if test="${obj==null }">
		<div class="form-group" id="manDiv0" >
			<input type="hidden" id="man0" value="${item.id }" name="projUserList[0].id" >
				<label class="col-sm-1 control-label">职位</label>
				<div class="col-sm-2">
					<select class="select2 form-control" size="1" dataType="*"
						name="projUserList[0].postId">
						<option value="">--请选择职位--</option>
						<c:forEach items="${postList}" var="it">
							<option value="${it.id }"  >${it.postName }</option>
						</c:forEach>
					</select>
					<div class="Validform_checktip"></div>
				</div>
				<label class="col-sm-1 control-label">人员</label>
				<div class="col-sm-2">
					<select class="select2 form-control" size="1" dataType="*"
						name="projUserList[0].userId">
						<option value="">--请选择人员--</option>
						<c:forEach items="${usersList}" var="it">
							<option value="${it.id }" <c:if test="${it.id eq user.id }"> selected="selected"  </c:if>>${it.name }</option>
						</c:forEach>
					</select>
					<div class="Validform_checktip"></div>
				</div>
				<label class="col-sm-1 control-label">工作时间</label>
				<div class="col-sm-3">
					<input type="text" dataType="*1-100"
						class="form-control datetimepicker0"
						style="width: 40%; float: left;" pattern="yyyy-MM-dd"
						id="beginTime0" name="projUserList[0].beginTime" value="<fmt:formatDate value="${item.beginTime }" pattern="yyyy-MM-dd" /> "
						ignore="ignore" />
					<div style="float: left;" class="form-control-static">到</div>
					<input type="text" dataType="*1-100"
						class="form-control datetimepicker0" value="<fmt:formatDate value="${item.endTime }" pattern="yyyy-MM-dd" /> "
						style="width: 40%; float: left;" pattern="yyyy-MM-dd"
						id="endTime0" name="projUserList[0].endTime" ignore="ignore" />
				</div>
				<div class="col-sm-2">
					<button onclick="delMan('manDiv0','man0')" class="btn btn-danger radius">删除</button>
				</div>
				</div>
		</c:if>
		
		<c:if test="${obj!=null }">
		<c:forEach items="${obj.projUserList }" var="item" varStatus="st">
			<div class="form-group" id="manDiv${st.index }" >
			<input type="hidden" id="man${st.index }" value="${item.id }" name="projUserList[${st.index }].id" >
				<label class="col-sm-1 control-label">职位</label>
				<div class="col-sm-2">
					<select class="select2 form-control" size="1" dataType="*"
						name="projUserList[${st.index }].postId">
						<option value="">--请选择职位--</option>
						<c:forEach items="${postList}" var="it">
							<option value="${it.id }"  <c:if test='${it.id eq item.postId }'> selected="selected"  </c:if> >${it.postName }</option>
						</c:forEach>
					</select>
					<div class="Validform_checktip"></div>
				</div>
				<label class="col-sm-1 control-label">人员</label>
				<div class="col-sm-2">
					<select class="select2 form-control" size="1" dataType="*"
						name="projUserList[${st.index }].userId">
						<option value="">--请选择人员--</option>
						<c:forEach items="${usersList}" var="it">
							<option value="${it.id }" <c:if test="${it.id eq item.userId }"> selected="selected"  </c:if>>${it.name }</option>
						</c:forEach>
					</select>
					<div class="Validform_checktip"></div>
				</div>
				<label class="col-sm-1 control-label">工作时间</label>
				<div class="col-sm-3">
					<input type="text" dataType="*1-100"
						class="form-control datetimepicker${st.index }"
						style="width: 40%; float: left;" pattern="yyyy-MM-dd"
						id="beginTime${st.index }" name="projUserList[${st.index }].beginTime" value="<fmt:formatDate value="${item.beginTime }" pattern="yyyy-MM-dd" /> "
						ignore="ignore" />
					<div style="float: left;" class="form-control-static">到</div>
					<input type="text" dataType="*1-100"
						class="form-control datetimepicker${st.index }" value="<fmt:formatDate value="${item.endTime }" pattern="yyyy-MM-dd" /> "
						style="width: 40%; float: left;" pattern="yyyy-MM-dd"
						id="endTime${st.index }" name="projUserList[${st.index }].endTime" ignore="ignore" />
				</div>
				<div class="col-sm-2">
					<button onclick="delMan('manDiv${st.index}','man${st.index }')" class="btn btn-danger radius">删除</button>
				</div>
			</div>
		</c:forEach>
		</c:if>
		
		</div>


		<div class="form-group ">
			<div class="col-sm-12 text-center">
				<a href="javascript:;" onclick="myForm.submit()"
					class="btn btn-success radius">保存</a>&nbsp;&nbsp;&nbsp;&nbsp;
				<button onclick="MTools.closeForm()" class="btn btn-danger radius">取消</button>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">
	MTools.ininDatetimepicker();
	MTools.limitStartEndTime();
	var myForm = MForm.initForm({
		invokeUrl : "${path}/admin/project/addOrModify",
		afterSubmit:function(){
			parent.myGrid.serchData();
		}
	});

	$(".select2").select2();
	//绑定点击事件
	$("#img_1").click(function() {
		$("#fileText").trigger("click");
	});

	//检测文件改变事件
	function fileChange() {
		if ($("#fileText").val() == '') {
			return;
		}
		$("#img_1").attr("src", basePath + "/resource/images/loadingbig.gif");
		$("#submitBtn").trigger("click");
	}

	/**
	 开始上传图片
	 **/
	function setPhoto() {
		console.log('开始上传图片');
		$("#photo").val($('#img_1').attr('src'));
	}
	
	var count = ${count};
	$(function(){ 
		for(var i=0;i<count;i++){
			MTools.ininDatetimepicker({
				timeSelecter : ".datetimepicker" + i
			});
			MTools.limitStartEndTime({
				beginTimeId : "#beginTime" + i,
				endTimeId : "#endTime" + i
			});
		}
	}); 
	function addMan() {
		$("#manbox").append($("#mantempINDEX").html().replace(/INDEX/g, count));
		MTools.ininDatetimepicker({
			timeSelecter : ".datetimepicker" + count
		});
		MTools.limitStartEndTime({
			beginTimeId : "#beginTime" + count,
			endTimeId : "#endTime" + count
		});
		$("#select"+count).select2();
		count++;
	}
	
	function delMan(divId,id) {
		if($("#"+id).val()==null ||$("#"+id).val()=='' ){
			$("#"+divId).remove();
		}else{
			MTools.handleItem("${path}/admin/project/delProjUser?keys=" + $("#"+id).val(), "确认要删除这条数据吗？",
			function() {
				$("#"+divId).remove();
			});
		}
	}

</script>

<div style="display: none" type="text/template" id="mantempINDEX">
	<div class="form-group" id="manDivINDEX" >
	<input type="hidden" id="manINDEX" >
		<label class="col-sm-1 control-label">职位</label>
		<div class="col-sm-2">
			<select class=" form-control" size="1" dataType="*"
				name="projUserList[INDEX].postId">
				<option value="">--请选择职位--</option>
				<c:forEach items="${postList}" var="item">
					<option value="${item.id }">${item.postName }</option>
				</c:forEach>
			</select>
			<div class="Validform_checktip"></div>
		</div>
		<label class="col-sm-1 control-label">人员</label>
		<div class="col-sm-2">
			<select class="form-control" size="1" id="selectINDEX" dataType="*"
				name="projUserList[INDEX].userId">
				<option value="">--请选择人员--</option>
				<c:forEach items="${usersList}" var="item">
					<option value="${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			<div class="Validform_checktip"></div>
		</div>
		<label class="col-sm-1 control-label">工作时间</label>
		<div class="col-sm-3">
			<input type="text" dataType="*"
				class="form-control datetimepickerINDEX"
				style="width: 40%; float: left;" pattern="yyyy-MM-dd"
				id="beginTimeINDEX" name="projUserList[INDEX].beginTime"
				ignore="ignore" />
			<div style="float: left;" class="form-control-static">到</div>
			<input type="text" dataType="*1-100"
				class="form-control datetimepickerINDEX"
				style="width: 40%; float: left;" pattern="yyyy-MM-dd"
				id="endTimeINDEX" name="projUserList[INDEX].endTime" ignore="ignore" />
		</div>
		<div class="Validform_checktip"></div>
		<div class="col-sm-2">
			<button onclick="delMan('manDivINDEX','manINDEX')" class="btn btn-danger radius">删除</button>
		</div>
	</div>
</div>




</body>
</html>